﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Globalization;
using System.Media;
using System.Configuration;

namespace teach
{

    //
    // PROF application main form. 
    //
    public partial class MainForm : Form
    {
        private const int PHILIPPE = 0;
        private const int SIMON = 1;

        public enum RESULT { GOOD, BAD };

        //private string videoPath = @"D:\imagesProf\videos\";
        //private string videoLongPath = @"D:\imagesProf\videosLong\";

        //private string history = @"D:\imagesProf\videos\history.txt";
        //private string history_long = @"D:\imagesProf\videosLong\history.txt";
        
        private Question m_currentQuestion = null;
        private int m_currentOption = PHILIPPE;
        private List<Question> m_wrongQuestions = new List<Question>();

        private List<QuestionType> m_questionType = new List<QuestionType>();
        public List<QuestionType>[] m_randomLists = new List<QuestionType>[2];

        private CultureInfo info = new CultureInfo("en-ca");

        private int questions = 0;
        private int goodAnswers = 0;
        private int streak = 0;
        private int numVideos = 0;
        private Random rnd = new Random();

        
        //
        // Main Constructor
        //
        public MainForm()
        {
            InitializeComponent();
            LoadQuestionsType();
            FillRandomLists();
            m_currentOption = PHILIPPE;

            GetNextQuestion();
            timerDelai.Interval = int.Parse(txtDelai.Text) * 1000;

            
        }

        public void Log(String line)
        {
            //StreamWriter writer = new StreamWriter("C:\\proflog.txt", true);
            //writer.WriteLine(line);
            //writer.Close();
        }

        /// <summary>
        /// Fill a random list
        /// </summary>
        private void FillRandomLists()
        {
            for (int i = 0; i < 2; i++)
            {
                m_randomLists[i] = new List<QuestionType>();
                foreach (QuestionType type in m_questionType)
                {
                    if (type.Settings[i].Enabled)
                    {
                        for (int j = 0; j < type.Settings[i].Weight; j++)
                        {
                            m_randomLists[i].Add(type);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// Parse operation node
        /// </summary>
        private Operation ParseOperationNode(XmlNode operationNode)
        {
            Operation operation = new Operation();
            operation.Name = operationNode.Name;
            operation.Enabled = bool.Parse(operationNode.SelectSingleNode("enabled").InnerText);
            operation.Min = int.Parse(operationNode.SelectSingleNode("min").InnerText);
            operation.Max = int.Parse(operationNode.SelectSingleNode("max").InnerText);
            operation.Timeout = int.Parse(operationNode.SelectSingleNode("timeout").InnerText);
            operation.Weight = int.Parse(operationNode.SelectSingleNode("weight").InnerText);
            return operation;
        }

        #region videos
        //
        // Get a short video
        //
        private void GetShortVideo()
        {
            DirectoryInfo infodir = new DirectoryInfo(ConfigurationManager.AppSettings["PathVideosGood"].ToString());
            FileInfo[] files = infodir.GetFiles("*.wmv");
            Random rnd = new Random();

            // load history file
            StreamReader reader = new StreamReader(ConfigurationManager.AppSettings["PathVideosGood"].ToString() + "/history.txt");
            List<string> historicLines = new List<string>();
            List<DateTime> historicDates = new List<DateTime>();
            string line = reader.ReadLine();

            while (line != null)
            {
                string datestr = line.Substring(0, 10);
                DateTime stamp = DateTime.Parse(datestr, info);

                TimeSpan span = DateTime.Now - stamp;
                if (span.TotalDays < int.Parse(ConfigurationManager.AppSettings["HistoryMaxDays"].ToString()))
                {
                    historicLines.Add(line.Substring(11));
                    historicDates.Add(stamp);
                }
                line = reader.ReadLine();
            }
            reader.Close();

            // pick a file
            int index = rnd.Next(files.Length);
            while (historicLines.Contains(files[index].Name))
            {
                index = rnd.Next(files.Length);
            }

            historicLines.Add(files[index].Name);
            historicDates.Add(DateTime.Now);
            StreamWriter writer = new StreamWriter(ConfigurationManager.AppSettings["PathVideosGood"].ToString() + "/history.txt", false);
            int count = historicLines.Count;
            for (int i = 0; i < count; i++)
            {
                writer.WriteLine(historicDates[i].ToString("yyyy-MM-dd") + " " + historicLines[i]);
            }
            writer.Close();

            player.Visible = true;
            player.URL = files[index].FullName;
            player.Ctlcontrols.play();
        }
        
        //
        // Get a long video
        //
        private void GetLongVideo()
        {
            DirectoryInfo infodir = new DirectoryInfo(ConfigurationManager.AppSettings["PathVideosLongGood"].ToString());
            FileInfo[] files = infodir.GetFiles("*.wmv");
            Random rnd = new Random();

            // load history file
            StreamReader reader = new StreamReader(ConfigurationManager.AppSettings["PathVideosLongGood"].ToString() + "/history.txt");
            List<string> historicLines = new List<string>();
            List<DateTime> historicDates = new List<DateTime>();
            string line = reader.ReadLine();

            while (line != null && line != string.Empty)
            {
                string datestr = line.Substring(0, 10);
                DateTime stamp = DateTime.Parse(datestr, info);

                TimeSpan span = DateTime.Now - stamp;
                if (span.TotalDays < int.Parse(ConfigurationManager.AppSettings["HistoryMaxDays"].ToString()))
                {
                    historicLines.Add(line.Substring(11));
                    historicDates.Add(stamp);
                }
                line = reader.ReadLine();
            }
            reader.Close();

            // pick a file
            int index = rnd.Next(files.Length);
            while (historicLines.Contains(files[index].Name))
            {
                index = rnd.Next(files.Length);
            }

            historicLines.Add(files[index].Name);
            historicDates.Add(DateTime.Now);
            string path = ConfigurationManager.AppSettings["PathVideosLongGood"].ToString() + "/history.txt";
            StreamWriter writer = new StreamWriter(path, false);
            int count = historicLines.Count;
            for (int i = 0; i < count; i++)
            {
                writer.WriteLine(historicDates[i].ToString("yyyy-MM-dd") + " " + historicLines[i]);
            }
            writer.Close();

            player.Visible = true;
            player.URL = files[index].FullName;
            player.Ctlcontrols.play();
        }
        #endregion

        //
        // Get an image depending on the result
        //
        private Image GetImage(RESULT result)
        {
            Image retour = null;
            switch (result)
            {
                case RESULT.GOOD:
                    DirectoryInfo info = new DirectoryInfo(ConfigurationManager.AppSettings["PathImagesGood"].ToString());
                    FileInfo[] goodImgs = info.GetFiles();
                    int idx = rnd.Next(goodImgs.Length);
                    retour = new Bitmap(goodImgs[idx].FullName);
                    break;
                case RESULT.BAD:
                    DirectoryInfo badinfo = new DirectoryInfo(ConfigurationManager.AppSettings["PathImagesBad"].ToString());
                    FileInfo[] badImgs = badinfo.GetFiles();
                    int bidx = rnd.Next(badImgs.Length);
                    retour = new Bitmap(badImgs[bidx].FullName);
                    break;
            }
            return retour;
        }

        //
        // Manage the click on the main button
        //
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (btnNext.Text == "RÉPONSE")
            {
                btnNext.Text = "PROCHAIN";
                CheckAnswer();
            }
            else
            {
                btnNext.Text = "RÉPONSE";
                txtName.Text = "Prof";
                GetNextQuestion();
            }
        }

        //
        // Update the application title
        //
        private void UpdateTitle()
        {
            this.Text = "PROF    (" + goodAnswers + " bonnes réponses sur " + questions + ")";
            if (numVideos == 1)
            {
                this.Text += "                  " + streak + " DE SUITE! / " + numVideos + " vidéo";
            }
            else
            {
                this.Text += "                  " + streak + " DE SUITE! / " + numVideos + " vidéos";
            }
        }

        /// <summary>
        /// Check the current answer
        /// </summary>
        private void CheckAnswer()
        {
            timerDelai.Enabled = false;
            questions++;
            int answer = 9999;
            string textAnswer = "";

            try
            {
                answer = int.Parse(txtAnswer.Text);
            }
            catch { }
            textAnswer = txtTextAnswer.Text.Trim().ToLower();
            if (m_currentQuestion.CheckAnswer(answer, textAnswer))
            {
                streak++;
                txtAnswer.ForeColor = Color.Blue;
                txtTextAnswer.ForeColor = Color.Blue;
                if (m_currentQuestion.Type.Name == "Choix")
                {
                    if (btnAnswerA.Text.ToLower() == textAnswer.ToLower())
                    {
                        btnAnswerA.ForeColor = Color.Blue;
                        btnAnswerC.Text = "PROCHAIN";
                    }
                    else if (btnAnswerB.Text.ToLower() == textAnswer.ToLower())
                    {
                        btnAnswerB.ForeColor = Color.Blue;
                        btnAnswerC.Text = "PROCHAIN";
                    }
                    else if (btnAnswerC.Text.ToLower() == textAnswer.ToLower())
                    {
                        btnAnswerC.ForeColor = Color.Blue;
                        btnAnswerB.Text = "PROCHAIN";
                    }
                }
                if (streak % 10 == 0)
                {
                    GetLongVideo();
                    numVideos++;
                    txtName.Text = "Wow!";
                }
                else if (streak % 5 == 0)
                {
                    GetShortVideo();
                    numVideos++;
                    txtName.Text = "Bravo!";
                }
                else
                {
                    pctStatus.Image = GetImage(RESULT.GOOD);
                    txtName.Text = "Cool!";
                }
                goodAnswers++;
            }
            else
            {
                streak = 0;
                pctStatus.Image = GetImage(RESULT.BAD);
                txtName.Text = "Ouch...";

                txtTextAnswer.ForeColor = Color.Red;
                txtTextAnswer.Text = m_currentQuestion.GetAnswer();

                if (btnAnswerA.Text == txtTextAnswer.Text)
                {
                    btnAnswerA.ForeColor = Color.Red;
                    btnAnswerC.Text = "PROCHAIN";
                }
                else if (btnAnswerB.Text == txtTextAnswer.Text)
                {
                    btnAnswerB.ForeColor = Color.Red;
                    btnAnswerC.Text = "PROCHAIN";
                }
                else if (btnAnswerC.Text == txtTextAnswer.Text)
                {
                    btnAnswerC.ForeColor = Color.Red;
                    btnAnswerB.Text = "PROCHAIN";
                }

                txtAnswer.ForeColor = Color.Red;
                if (m_currentQuestion.isNumeric())
                {
                    txtGoodAnswer.Visible = true;
                    txtFinalAnswer.Visible = true;
                    txtFinalAnswer.Text = m_currentQuestion.GetAnswer();
                }
                if (m_currentQuestion.Type.Name != "Math")
                {
                    m_wrongQuestions.Add(m_currentQuestion);
                }
            }

            UpdateTitle();
        }

        /// <summary>
        /// Reset the UI for the next question
        /// </summary>
        private void ResetUIForNextQuestion()
        {
            player.Visible = false;
            txtAnswer.Text = "";
            txtTextAnswer.Text = "";
            pctStatus.Image = null;
            pctStatus.Refresh();
            txtGoodAnswer.Visible = false;
            txtFinalAnswer.Visible = false;
        }

        /// <summary>
        /// Get a new sign
        /// </summary>
        /// <param name="option">The current sign</param>
        /// <returns>The next sign</returns>
        private QuestionType GetNextType()
        {
            int signrandom = rnd.Next(m_randomLists[m_currentOption].Count);
            return m_randomLists[m_currentOption][signrandom];
        }


        /// <summary>
        /// Generate a new question
        /// </summary>
        /// <returns></returns>
        private Question GetNewQuestion()
        {
            Question newQuestion = new Question();
            newQuestion.Type = GetNextType();
            Log("TYPE: " + newQuestion.Type.Name);
            newQuestion.GenerateQuestion(m_currentOption);
            newQuestion.Timeout = newQuestion.Type.Settings[m_currentOption].Timeout * 1000;
            return newQuestion;
        }

        /// <summary>
        /// Get the next PROF question
        /// </summary>
        private void GetNextQuestion()
        {
            ResetUIForNextQuestion();

            // PREVIOUS ERRORS?
            int num = rnd.Next(15);
            if (m_wrongQuestions.Count > 2 && num > 12)
            {
                txtName.Text = "Révision";
                m_currentQuestion = m_wrongQuestions[rnd.Next(m_wrongQuestions.Count)];
                Log("Révision");
            }
            else if (m_wrongQuestions.Count > 0 && num == 8)
            {
                txtName.Text = "Révision";
                m_currentQuestion = m_wrongQuestions[rnd.Next(m_wrongQuestions.Count)];
                Log("Révision");
            }
            else
            {
                Log("New Question");
                m_currentQuestion = GetNewQuestion();
            }
            UpdateUI(m_currentQuestion.Type);
            if (m_currentQuestion.isNumeric())
            {
                txtSign.Text = m_currentQuestion.GetSign();
                txtFirst.Text = m_currentQuestion.First.ToString();
                txtSecond.Text = m_currentQuestion.Second.ToString();
                this.ActiveControl = txtAnswer;
            }
            else 
            {
                txtName.Text = m_currentQuestion.Type.Name;
                txtAnswer.Text = m_currentQuestion.GetTextQuestion();
                if (txtAnswer.Text.Contains(".png"))
                {
                    string path = ConfigurationManager.AppSettings["PathImagesQuestion"].ToString() + "\\" + txtAnswer.Text;
                    Image question = new Bitmap(path);
                    pctStatus.Image = question;
                }
                else if (m_currentQuestion.Type.Name == "Choix")
                {
                    string[] choices = m_currentQuestion.GetChoices();
                    btnAnswerA.Text = choices[0];
                    btnAnswerB.Text = choices[1];
                    btnAnswerC.Text = choices[2];

                }
                this.ActiveControl = txtTextAnswer;
            }

            txtTextAnswer.ForeColor = Color.Black;
            txtAnswer.ForeColor = Color.Black;
            timerDelai.Interval = m_currentQuestion.Timeout;
            timerDelai.Enabled = true;
            
        }

        /// <summary>
        /// Trop tard...
        /// </summary>
        private void timerDelai_Tick(object sender, EventArgs e)
        {
            timerDelai.Enabled = false;
            btnNext.Text = "PROCHAIN";
            //numVideos = 0;
            CheckAnswer();
        }

        private void rbPhil_CheckedChanged(object sender, EventArgs e)
        {
            m_currentOption = PHILIPPE;
            txtName.Text = "Philippe";
            numVideos = 0;
            CleanUp();
            UpdateTitle();
        }

        private void rbSimon_CheckedChanged(object sender, EventArgs e)
        {
            m_currentOption = SIMON;
            txtName.Text = "Simon";
            CleanUp();
            UpdateTitle();
        }

        private void CleanUp()
        {
            m_wrongQuestions.Clear();
            questions = 0;
            goodAnswers = 0;
            streak = 0;
            btnNext.Text = "RÉPONSE";
            GetNextQuestion();
        }


        /// <summary>
        /// Load the questions type
        /// </summary>
        private void LoadQuestionsType()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Application.StartupPath + "\\" + "types.xml");
            XmlNodeList itemList = doc.DocumentElement.SelectNodes("type");
            foreach (XmlNode node in itemList)
            {
                QuestionType type = new QuestionType();
                type.StartupPath = Application.StartupPath;
                type.Name = node.SelectSingleNode("Name").InnerText;
                type.UI = node.SelectSingleNode("UI").InnerText;
                type.File = node.SelectSingleNode("File").InnerText;
                type.Settings[PHILIPPE] = ParseOperationNode(node.SelectSingleNode("Philippe"));
                type.Settings[SIMON] = ParseOperationNode(node.SelectSingleNode("Simon"));
                m_questionType.Add(type);
            }
        }

        /// <summary>
        /// switch UI to text mode
        /// </summary>
        /// <param name="text"></param>
        private void UpdateUI(QuestionType type)
        {
            switch (type.UI)
            {
                case "AUDIO":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    txtSign.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAnswerC.Visible = false;
                    btnAudio.Visible = true;
                    btnNext.Visible = true;
                    txtAnswer.Visible = false;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    break;
                case "HYBRID":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    txtSign.Visible = false;
                    btnAudio.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAnswerC.Visible = false;
                    btnNext.Visible = true;
                    txtAnswer.Visible = false;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    break;

                case "TEXT":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    txtSign.Visible = false;
                    btnAudio.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32,188);
                    txtAnswer.Size = new Size(616, 80);
                    txtAnswer.ReadOnly = true;
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnNext.Visible = true;
                    btnAnswerC.Visible = false;
                    txtAnswer.Visible = true;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 40F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                break;

                case "MATH":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    btnAudio.Visible = false;
                    txtSign.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    txtAnswer.ReadOnly = true;
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAnswerC.Visible = false;
                    txtAnswer.Visible = true;
                    btnNext.Visible = true;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                break;

                case "HISTORY":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    btnAudio.Visible = false;
                    txtSign.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    txtAnswer.ReadOnly = true;
                    btnNext.Visible = true;
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAnswerC.Visible = false;
                    txtAnswer.Visible = true;
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                break;

                case "UNITS":
                    txtTextAnswer.Visible = true;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    txtSign.Visible = false;
                    txtEqual.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    txtAnswer.ReadOnly = true;
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAudio.Visible = false;
                    btnAnswerC.Visible = false;
                    btnNext.Visible = true;
                    txtAnswer.Visible = true;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                break;

                case "OPERATION":
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    txtTextAnswer.Visible = false;
                    txtFirst.Visible = true;
                    txtSecond.Visible = true;
                    txtSign.Visible = true;
                    txtEqual.Visible = true;
                    btnNext.Location = new Point(206, 286);
                    txtAnswer.Location = new Point(500, 188);
                    txtAnswer.Size = new Size(146,80);
                    txtAnswer.Visible = true;
                    btnAudio.Visible = false;
                    txtAnswer.ReadOnly = false;
                    btnAnswerA.Visible = false;
                    btnAnswerB.Visible = false;
                    btnAnswerC.Visible = false;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    btnNext.Visible = true;
                break;

                case "CHOICES":
                    btnAnswerA.Visible = true;
                    btnAnswerA.ForeColor = Color.Black;
                    btnAnswerB.Visible = true;
                    btnAnswerB.ForeColor = Color.Black;
                    btnAnswerC.Visible = true;
                    btnAnswerC.ForeColor = Color.Black;
                    txtTextAnswer.Visible = false;
                    txtFirst.Visible = false;
                    txtSecond.Visible = false;
                    txtSign.Visible = false;
                    txtEqual.Visible = false;
                    btnAudio.Visible = false;
                    btnNext.Location = new Point(417, 284);
                    txtAnswer.Location = new Point(32, 188);
                    txtAnswer.Size = new Size(616, 80);
                    txtAnswer.ReadOnly = true;
                    txtAnswer.Visible = true;
                    btnNext.Visible = false;
                    this.txtTextAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                break;
            }
        }

        private void btnAnswerA_Click(object sender, EventArgs e)
        {
            if (btnAnswerA.Text == "PROCHAIN")
            {
                btnNext.Text = "RÉPONSE";
                txtName.Text = "Prof";
                GetNextQuestion();
            }
            else if (btnAnswerB.Text != "PROCHAIN" && btnAnswerC.Text != "PROCHAIN")
            {
                txtTextAnswer.Text = btnAnswerA.Text;
                CheckAnswer();
            }
        }

        private void btnAnswerB_Click(object sender, EventArgs e)
        {
            if (btnAnswerB.Text == "PROCHAIN")
            {
                btnNext.Text = "RÉPONSE";
                txtName.Text = "Prof";
                GetNextQuestion();
            }
            else if (btnAnswerA.Text != "PROCHAIN" && btnAnswerC.Text != "PROCHAIN")
            {
                txtTextAnswer.Text = btnAnswerB.Text;
                CheckAnswer();
            }
        }

        private void btnAnswerC_Click(object sender, EventArgs e)
        {
            if (btnAnswerC.Text == "PROCHAIN")
            {
                btnNext.Text = "RÉPONSE";
                txtName.Text = "Prof";
                GetNextQuestion();
            }
            else if (btnAnswerB.Text != "PROCHAIN" && btnAnswerA.Text != "PROCHAIN")
            {
                txtTextAnswer.Text = btnAnswerC.Text;
                CheckAnswer();
            }
        }

        private void btnAudio_Click(object sender, EventArgs e)
        {
            string path = ConfigurationManager.AppSettings["PathAudioQuestion"].ToString() + "\\" + "jevais.wav";
            string audio = Application.StartupPath + "\\questions\\audio\\" + "jevais.wav";
            SoundPlayer simpleSound = new SoundPlayer(audio);
            simpleSound.Play();
        }
    }
}
